<!DOCTYPE html>
<meta charset="UTF-8">

<div  style="height: 100%; overflow: auto">
	<form class="form-horizontal" style="padding-top: 18px">
		<div class="form-group"
			style="width: 1100px; height: 40px; margin-bottom: 0px">
			<div class="col-md-3">
				<span class='h3'>个人成绩录入<small>PersonGrade</small></span>
			</div>
			<label class="col-md-1 control-label">选择班级</label>
			<div class="col-md-2">
				<input class="form-control" type="text" name="bjSel" id="bjSel" value="" />
			</div>
			<label class="col-md-1 control-label">选择学生</label>
			<div class="col-md-2">
				<input disabled class="form-control" type="text" name="xsSel" id="xsSel" value="" />
			</div>
			<button type="button" onclick="cx()" class="btn btn-default col-md-1"><span class="glyphicon glyphicon-search"></span> 查询</button>
		</div>
	</form>
	<hr>
	<div id='aa' style="display: none">
		<table id="mytable"></table>
	</div>
</div>
<script type="text/javascript">
		$(function(){
			$('#bjSel').combobox({
				url:'tbclass/list',
				textField: 'name',
				valueField: 'id',
				hidebtn:function(){
					$('#aa').hide();
					$('#xsSel').combobox('destroy');
					$('#xsSel').val('');
				},
				onchange:function(newsel){
					$('#aa').hide();
					var bjId=newsel;
					$('#xsSel').combobox('destroy');
					$('#xsSel').combobox({
						url:'xuesheng/list?bjId='+bjId,
						textField: 'name',
						valueField: 'id',
						hidebtn:function(){
							$('#aa').hide();
						},
						onchange:function(newsel){
							$('#aa').hide();
						}
					})
					$('#xsSel').combobox('setNull');
				}
			})
		})
		
		function shuaxin(bjId,xsId){
			$('#mytable').datagrid({
				url:'page2?bjId='+bjId+"&xsId="+xsId,
				path:'grade',
				search: false, 
				showColumns:false, 
				showRefresh: false,  
				showToggle: false, 
				columns:[
					[
						{title:'课程',field:'course',width:400,formatter:function(value,row,index){
		            		return row.course.name;}},
						{title:'成绩',field:'grade',width:300,formatter:function(value,row,index){
							if(!row.grade){
								row.grade=0;
							}
						   return '<input style="height:25px" onchange="xg('+row.id+',this)" class="form-control"  name="ipt" value="'+row.grade+'"/>'
						}}
					]		
				],
				buttons:[]
			})
	}
		
	function cx(){
		var bjId=$('#bjSel').combobox('getValue');
		var xsId=$('#xsSel').combobox('getValue');
		if(bjId==""||xsId==""){
			return;
		}
		$('#aa').text('');
		var table=$('<table id="mytable"/>')
		table.appendTo($('#aa'));
		shuaxin(bjId,xsId);
		$('#aa').show();
	}
	
	function xg(id,obj){
		grade=$(obj).val();
		if(!(/^[0-9]\d*$/.test(grade))){
			bootbox.alert('请输入正整数');
			return;
		};
	$.post('grade/classCjxg',{id:id,grade:grade},function(data){
			if(data.success){
				$.messagebox(data.msg,2000);
			}else{
				bootbox.alert(data.msg);
			}
		});
	}
</script>
	